%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%openDACS projects%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Optimize function written for A-IGZO TETs
%%% Print parameters or self-generate Verilog-A
%%% About a-IGZO devices and models,pls refer 10.1063/1.4922181,10.1109/TED.2021.3054359
%%% developed by Jingrui Guo,Lingfei Wang,and Ling Li from IME-CAS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [coeff_op] = optimize_data(coeff_init)
% for parameters to be optimized we read the experimental data set
clear Id_data
clear bias_data Vg_data Vd_data
clear Vg* Vd* 
global IdVg Id_data TolFun
Id_data = IdVg(1:end,3); % Amp/meters
Vg_data=IdVg(1:end,1);
Vd_data=IdVg(1:end,2);
bias_data(:,1)=Vg_data;
bias_data(:,2)=Vd_data;

%%%%% now we run optimization. Make a matrix of initial guess
options = optimset('Display','iter','TolFun',TolFun);
lb = [340;1e17  ;0.1;0.1;0.1;-1;10;0;0;1.01;0]; % lower-bound constraints
ub = [420;1.5e17;10 ;10 ;10 ;2 ;50;2;2;2;1]; % upper-bound constraints
%%%% Optimization routine 
[coeff_op,resnorm,residual,exitflag,output] = lsqcurvefit(@OD_TFT_v_1_0_3,coeff_init,bias_data,Id_data,lb,ub,options); 
end
